package com.mallcai.bigdata.ladon.dpl.mapper.report;

import com.mallcai.bigdata.ladon.dpl.entity.report.ReportRlGroup;
import com.mallcai.bigdata.ladon.dpl.mapper.report.provider.ReportRlGroupSqlProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author gst
 * @date 2019-12-30 20:36
 */
@Repository
public interface ReportRlGroupMapper {
    @InsertProvider(type = ReportRlGroupSqlProvider.class, method = "insert")
    int insert(ReportRlGroup reportRlGroup);

    @UpdateProvider(type = ReportRlGroupSqlProvider.class, method = "update")
    int update(ReportRlGroup reportRlGroup);

    @DeleteProvider(type = ReportRlGroupSqlProvider.class, method = "delete")
    int delete(ReportRlGroup reportRlGroup);

    @Select({
            "SELECT * FROM " + ReportRlGroupSqlProvider.TB_REPORT_RL_GROUP + " WHERE archive = 0 AND group_id = #{groupId}"
    })
    List<ReportRlGroup> getByGroupId(@Param("groupId") Long groupId);

    @Select({
            "SELECT group_id FROM " + ReportRlGroupSqlProvider.TB_REPORT_RL_GROUP + " WHERE archive = 0 AND report_id = #{reportId}"
    })
    List<Long> getGroupIdsByReportId(@Param("reportId") Long reportId);

    @Delete({
            "DELETE FROM " + ReportRlGroupSqlProvider.TB_REPORT_RL_GROUP + " WHERE report_id = #{reportId}"
    })
    int delByReportId(@Param("reportId") Long reportId);
}
